package com.tourism.product.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.tourism.product.domain.ProductReview;
import com.tourism.product.service.IProductReviewService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品品论Controller
 * 
 * @author silenceEcho
 * @date 2025-04-13
 */
@RestController
@RequestMapping("/review")
public class ProductReviewController extends BaseController
{
    @Autowired
    private IProductReviewService productReviewService;

    /**
     * 查询产品品论列表
     */
    @RequiresPermissions("product:review:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductReview productReview)
    {
        startPage();
        List<ProductReview> list = productReviewService.selectProductReviewList(productReview);
        return getDataTable(list);
    }

    /**
     * 导出产品品论列表
     */
    @RequiresPermissions("product:review:export")
    @Log(title = "产品品论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductReview productReview)
    {
        List<ProductReview> list = productReviewService.selectProductReviewList(productReview);
        ExcelUtil<ProductReview> util = new ExcelUtil<ProductReview>(ProductReview.class);
        util.exportExcel(response, list, "产品品论数据");
    }

    /**
     * 获取产品品论详细信息
     */
    @RequiresPermissions("product:review:query")
    @GetMapping(value = "/{reviewId}")
    public AjaxResult getInfo(@PathVariable("reviewId") Long reviewId)
    {
        return success(productReviewService.selectProductReviewByReviewId(reviewId));
    }

    /**
     * 新增产品品论
     */
    @RequiresPermissions("product:review:add")
    @Log(title = "产品品论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductReview productReview)
    {
        return toAjax(productReviewService.insertProductReview(productReview));
    }

    /**
     * 修改产品品论
     */
    @RequiresPermissions("product:review:edit")
    @Log(title = "产品品论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductReview productReview)
    {
        return toAjax(productReviewService.updateProductReview(productReview));
    }

    /**
     * 删除产品品论
     */
    @RequiresPermissions("product:review:remove")
    @Log(title = "产品品论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reviewIds}")
    public AjaxResult remove(@PathVariable Long[] reviewIds)
    {
        return toAjax(productReviewService.deleteProductReviewByReviewIds(reviewIds));
    }
}
